package com.google.samples.apps.databinging.login

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.google.samples.apps.databinging.BR
import com.google.samples.apps.databinging.R
import com.google.samples.apps.databinging.databinding.ActivityLoginBinding
import com.google.samples.apps.library_common.utils.LogUtils
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity : AppCompatActivity() {

    lateinit var loginModel: LoginModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding =
            DataBindingUtil.setContentView<ActivityLoginBinding>(this, R.layout.activity_login)

        loginModel = LoginModel()

//        binding.setVariable(BR.viewModel, loginModel)
        binding.viewModel = loginModel
        binding.setVariable(BR.click, Click())
//        binding.setViewMode
    }

    inner class Click {
        fun login(view: View) {
            val userName = loginModel.userName.get()
            LogUtils.d("userName=$userName,editText=${editText.text}")
            Toast.makeText(
                view.context,
                "${userName}",
                Toast.LENGTH_SHORT
            ).show()
        }
    }

}